<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎</title>
    <th:block th:include="include::header"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" th:object="${work}">
            <input type="hidden" id="id" name="id" th:value="*{id}" required="" lay-verify="">
            <div class="layui-form-item">
                <label for="number" class="layui-form-label">
                    <span class="x-red"></span>工序号</label>
                <div class="layui-input-inline">
                    <input type="text" id="number" disabled="disabled" th:value="*{number}" name="number" required="" lay-verify=""
                           autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="production" class="layui-form-label">
                    <span class="x-red"></span>产额</label>
                <div class="layui-input-inline">
                    <input type="text" id="production" th:value="*{production}" name="production" required="" lay-verify="number"
                           autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">设备</label>
                <div class="layui-input-inline">
                    <select id="name" name="name" lay-verify="required" class="select">
                        <th:block th:each="item:${workList}" th:object="${item}">
                            <option th:value="*{type}" th:selected="${work.name==item.type?'true':'false'}">[[*{type}]]</option>
                        </th:block>
                    </select>
                </div>
            </div>
            <!--富文本编辑-->
            <div class="layui-form-item">
                <div id="summernote"></div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="edit" lay-submit="">修改</button>
            </div>
        </form>
    </div>
</div>
<script th:inline="javascript" type="text/javascript">

    // 初始化富文本
    $(document).ready(function () {
        $('#summernote').summernote();
    });
    //赋值
    var intro = [[${work.getIntro()}]];
    $('#summernote').summernote('code', intro);

</script>
<script>layui.use(['form', 'layer', 'jquery'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        //监听提交
        form.on('submit(edit)',
            function (data) {
                var summernote = $("#summernote").summernote("code");
                data.field.intro=summernote;
                console.log(data);
                console.log(data.field);
                //发异步，把数据提交给php
                $.ajax({
                    url: "/dispatch/edit",
                    type: "POST",
                    data: data.field,
                    success(res) {
                        if (res.success) {
                            layer.msg("修改成功", {
                                    icon: 6,
                                    time: 600
                                },
                                function () {
                                    //关闭当前frame
                                    xadmin.close();
                                });
                        } else {
                            layer.msg(res.msg)
                        }
                    }
                })
                return false;
            });

    });</script>
</body>

</html>